﻿var FileUploadHelper = new Object();
    FileUploadHelper.configurar     = _configurar;

var _handler            = "";
var _idBtnDisparador    = "";

function _configurar(handler, idBtnDisparador, showLoadingFn, hideLoadingFn, onResponseCallback)
{
    _handler            = handler;
    _idBtnDisparador    = idBtnDisparador;

    var btnDisparador = $("#" + _idBtnDisparador);

    $.ajax_upload(btnDisparador,
	{
	    action: _handler,
	    name:   'myfile',
	    onSubmit: function(file, ext)
	    {
            showLoadingFn.call(this);
	        /* To allow uploading only 1 file at time, you can disable upload button */
	        this.disable();
	    },
	    onComplete: function(file, response)
	    {
            hideLoadingFn.call(this);
            this.enable();
            if ( onResponseCallback != null )
	            onResponseCallback.call(this, response);
	    }
	});
    $("input:file").css({ cursor: "pointer" });
}
